﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel;

namespace Utility
{
    public class CUtility
    {
        public static Service.ServiceClient GetServiceClient()
        {
            Uri serviceUri = new Uri(Application.Current.Host.Source, "/Service.svc");
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.MaxBufferSize = int.MaxValue;

            Service.ServiceClient client = new Service.ServiceClient(binding, new EndpointAddress(serviceUri));
            return client;
        }

        public static Color ColorTranslator(string name)
        {
            string val = name.Replace("#", "");
            byte a = Convert.ToByte("ff", 16);
            int pos = 0;
            if (name.Length == 8)
            {
                a = Convert.ToByte(val.Substring(pos, 2), 16);
                pos = 2;
            }
            byte r = Convert.ToByte(val.Substring(pos, 2), 16);
            pos += 2;

            byte g = Convert.ToByte(val.Substring(pos, 2), 16);
            pos += 2;

            byte b = Convert.ToByte(val.Substring(pos, 2), 16);
            pos += 2;

            Color color = Color.FromArgb(a, r, g, b);
            return color;
        }
    }
}
